package com.mofang.powerdekorhelper.activity.activity;

import android.view.View;
import android.widget.TextView;

import com.mofang.powerdekorhelper.R;
import com.mofang.powerdekorhelper.base.MvpActivity;
import com.mofang.powerdekorhelper.model.ActivityInfo;
import com.mofang.powerdekorhelper.persenter.ActivityManagerPersenter;
import com.mofang.powerdekorhelper.utils.LoadPrograss;
import com.mofang.powerdekorhelper.utils.T;
import com.mofang.powerdekorhelper.view.ActivityManagerView;
import com.mofang.powerdekorhelper.witget.TitleBar;

import butterknife.BindView;

/**
 * Created by luofei on 2017/8/24 0024.
 */

public class ActivityManagerAct extends MvpActivity<ActivityManagerView, ActivityManagerPersenter> implements ActivityManagerView {

    @BindView(R.id.activity_manager_titlebar)
    TitleBar mTitleBar;

    @BindView(R.id.activity_manager_code)
    TextView codeTv;

    @BindView(R.id.activity_manager_name)
    TextView nameTv;

    @BindView(R.id.activity_info_share_num)
    TextView shareNumTv;

    @BindView(R.id.activity_info_invilite_num)
    TextView inviliteNumTv;

    @BindView(R.id.activity_info_sign_num)
    TextView signNumTv;

    @BindView(R.id.activity_info_sale_num)
    TextView saleNumTv;

    @BindView(R.id.activity_info_deposit_num)
    TextView depositNumTv;

    @BindView(R.id.activity_info_order_num)
    TextView orderNumTv;

    LoadPrograss loadPrograss;

    Integer activityId;
    String activityCode;
    String activityName;

    @Override
    public void initView() {
        inflateLayout(R.layout.activity_manager_layout);
        initTitleBarWithback(mTitleBar, R.string.activity_manager);
        loadPrograss = new LoadPrograss(this);
    }

    @Override
    public void initData() {

        activityId = getIntent().getIntExtra("ActivityId", -1);
        activityCode = getIntent().getStringExtra("ActivityCode");
        activityName = getIntent().getStringExtra("ActivityName");
        codeTv.setText(activityCode);
        nameTv.setText(activityName);

        presenter.getActivityInfo(activityId);
    }

    @Override
    public void setActivityInfo(ActivityInfo activityInfo) {

        if (activityInfo.getResult().getShareNum() != null) {
            shareNumTv.setText(activityInfo.getResult().getShareNum() + "");
        } else {
            shareNumTv.setText("0");
        }

        if (activityInfo.getResult().getInviteNum() != null) {
            inviliteNumTv.setText(activityInfo.getResult().getInviteNum() + "");
        } else {
            inviliteNumTv.setText("0");
        }

        if (activityInfo.getResult().getSignNum() != null) {
            signNumTv.setText(activityInfo.getResult().getSignNum() + "");
        } else {
            signNumTv.setText("0");
        }

        if (activityInfo.getResult().getCardNum() != null) {
            saleNumTv.setText(activityInfo.getResult().getCardNum() + "");
        } else {
            saleNumTv.setText("0");
        }

        if (activityInfo.getResult().getDeposit_price() != null) {
            depositNumTv.setText(activityInfo.getResult().getDeposit_price() + "");
        } else {
            depositNumTv.setText("0");
        }

        if (activityInfo.getResult().getOrderNum() != null) {
            orderNumTv.setText(activityInfo.getResult().getOrderNum() + "");
        } else {
            orderNumTv.setText("0");
        }

        hideProgress();
    }

    @Override
    public void showProgress() {
        loadPrograss.show();
    }

    @Override
    public void hideProgress() {
        loadPrograss.hide();
    }

    @Override
    public void toast(CharSequence s) {
        T.showShort(this, s);
    }

    @Override
    public void toast(int id) {

    }

    @Override
    public void showNullLayout() {

    }

    @Override
    public void hideNullLayout() {

    }

    @Override
    public void showErrorLayout(View.OnClickListener listener) {

    }

    @Override
    public void hideErrorLayout() {

    }

    @Override
    public void onError(String errorInfo) {
        hideProgress();
        toast(errorInfo);
    }

    @Override
    public ActivityManagerPersenter initPresenter() {
        return new ActivityManagerPersenter();
    }
}
